package com.czy.fx.day1.group;

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.stage.Stage;
/*讲解group容器，添加和移除子组件的方式，子组件设置位置等*/
public class demo1 extends Application {
    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) throws Exception {
        primaryStage.setTitle("地磅管理系统");
        primaryStage.setWidth(500);
        primaryStage.setHeight(500);

        Group group = new Group();
        Scene scene = new Scene(group);
        primaryStage.setScene(scene);

        Button b1 = new Button("b1");
        b1.setLayoutX(100);
        b1.setLayoutY(100);
        Button b2 = new Button("b2");
        b2.setLayoutX(200);
        b2.setLayoutY(100);
        Button b3 = new Button("b3");
        b3.setLayoutX(300);
        b3.setLayoutY(100);
        group.getChildren().addAll(b1, b2, b3);
        //移除group下所有组件
        //group.getChildren().clear();
        //移除group下指定组件
        group.getChildren().remove(b3);
        //获取group下所有组件
        Object[] array = group.getChildren().toArray();
        for (Object o : array) {
            if (o instanceof Button) {
                Button b = (Button) o;
                System.out.println("获取到按钮："+b.getText());
            }
        }
        primaryStage.show();

    }
}
